// trap.c 
#include "proc.h"
#include "printk.h"
#include "sbi.h"
#include "clock.h"
// unsigned long TIMECLOCK = 0x30000;
static int cnt = 0;

void trap_handler(unsigned long scause, unsigned long sepc) {
    switch(scause >> 63){ //Highest bit
        case 1: //Interrupt
            switch (scause & 0x7FFFFFFFFFFFFFFF){
                case 5: //Supervisor Mode Timer Interrupt
                    clock_set_next_event();
                    do_timer();
                    break;
                default:
                    break;
            }
            break;
        case 0: //Exception
            if(!cnt)printk("I LOVE SYS!\n");
            cnt = 1;
            break;
    }
    return;
}